package com.fulihui.wgj.dal.mybatis.repository;

import com.fulihui.wgj.dal.mybatis.domain.WxSubscribeReplyRule;
import com.fulihui.wgj.dal.mybatis.mapper.WxSubscribeReplyRuleMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wang_wx
 * @date 2018-06-20
 */
@Component
public class WxSubscribeReplyRuleRepository extends BaseRepository<WxSubscribeReplyRule> {

    @Resource
    WxSubscribeReplyRuleMapper wxSubscribeReplyRuleMapper;

    /**
     * 查询回复规则
     *
     * @param appId
     * @param useType
     * @return
     */
    public List<WxSubscribeReplyRule> queryByAppIdAndUseType(String appId, Integer useType) {
        Example example = new Example(WxSubscribeReplyRule.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotBlank(appId)) {
            criteria.andEqualTo("appId", appId);
        }
        if (null != useType) {
            criteria.andEqualTo("useType", useType);
        }
        return wxSubscribeReplyRuleMapper.selectByExample(example);
    }

    /**
     * 查询回复规则
     *
     * @param appId
     * @return
     */
    public List<WxSubscribeReplyRule> queryByAppId(String appId) {
        Example example = new Example(WxSubscribeReplyRule.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotBlank(appId)) {
            criteria.andEqualTo("appId", appId);
        }
        return wxSubscribeReplyRuleMapper.selectByExample(example);
    }

    /**
     * 查询回复规则-有效
     *
     * @param appId
     * @return
     */
    public List<WxSubscribeReplyRule> queryByAppIdAndUseful(String appId) {
        Example example = new Example(WxSubscribeReplyRule.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotBlank(appId)) {
            criteria.andEqualTo("appId", appId);
        }
        criteria.andEqualTo("useful", 1);
        return wxSubscribeReplyRuleMapper.selectByExample(example);
    }
}